package com.zhu.salesmanagement;


import com.zhu.location.R;
import com.zhu.salesmanagement.common.Actions;
import com.zhu.salesmanagement.models.RemindItemInfo;
import com.zhu.salesmanagement.provider.SalesSettings;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

public class RemindContentActivity extends Activity implements View.OnClickListener{

	private RemindItemInfo mInfo = null;
	private TextView mContentView = null;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.layout_remindcontent);

        Parcelable parcelable = getIntent().getParcelableExtra("info");
        mInfo = (RemindItemInfo) parcelable;

        setupView();
        initData();
    }

	private void setupView(){
		findViewById(R.id.remindcontent__bottom_back).setOnClickListener(this);
    	findViewById(R.id.remindcontent_back).setOnClickListener(this);
    	mContentView = (TextView)findViewById(R.id.remindcontent_content);
    }

    private void initData(){
    	mContentView.setText(mInfo.mName);
    }

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		if(arg0 != null){
        	switch(arg0.getId()){
        		case R.id.remindcontent_back:
        			finish();
        			break;
        		case R.id.remindcontent__bottom_back:
        			delete();
        			break;
        	}
		}
	}

	private void delete(){
		String where = "";
        String eventWhere = "";
        if (where.length() == 0) {
        	where += SalesSettings.RemindsColumns._ID + " = " + mInfo.id;
        	eventWhere += SalesSettings.RemindsColumns._ID + " = " + mInfo.eventId;
        } else {
        	where += " or " + SalesSettings.RemindsColumns._ID + " = " + mInfo.id;
        	eventWhere += " or " +SalesSettings.RemindsColumns._ID + " = " + mInfo.eventId;
        }
        Actions.deleteEvent(this, eventWhere);
        getContentResolver().delete(SalesSettings.RemindsColumns.CONTENT_URI, where, null);
        Actions.toastShort(this, getResources().getString(R.string.delete_success));
        setResult(RESULT_OK);
        finish();
	}
}
